<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1500" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-header>
                <div class="left-panel">
                    <!-- <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'project.add'"></el-button> -->
                </div>
                <div class="right-panel">
                    <div class="right-panel-search" style="flex-wrap:wrap;">
                        <!-- <el-input v-model="search.task_name" placeholder="任务名称" clearable @keyup.enter="upsearch"></el-input>
                        <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-refresh" @click="refresh">重置</el-button> -->
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :data="data" hidePagnation highlight-current-row @row-click="selectionChange" remoteSort remoteFilter border height="600">
                    <el-table-column width="1"></el-table-column>
                    <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                    <el-table-column label="用户" prop="user.real_name" align="center"></el-table-column>
                    <el-table-column label="领取时间" prop="create_time" align="center"></el-table-column>
                    <el-table-column label="签到时间" prop="sign_in_time" align="center"></el-table-column>
                    <el-table-column label="签退时间" prop="sign_out_time" align="center"></el-table-column>
                    <el-table-column label="任务时长" prop="long_time" align="center"></el-table-column>
                    <el-table-column label="状态" prop="status" align="center">
                        <template #default="scope">
                            <!-- {{scope.row.status == 1 ?'申请取消':''}} -->
                            <el-tag type="danger" v-if="scope.row.status == 1">申请取消</el-tag>
                            <el-tag type="info" v-if="scope.row.status == 2">已取消</el-tag>
                            <el-tag type="primary" v-if="scope.row.status == 0">正常</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="160">
                        <template #default="scope">
                            <el-button-group>
                                <el-popconfirm title="确定同意此申请吗？" @confirm="table_yes(scope.row, scope.$index)">
                                    <template #reference>
                                        <el-button text type="primary" size="small" v-if="scope.row.status == 1">同意</el-button>
                                    </template>
                                </el-popconfirm>
                            </el-button-group>
                        </template>
				</el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
        <save-add v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-add>
	</el-dialog>
</template>

<script>
import saveAdd from './save.vue'
export default {
    props:{
        query: { type: Object, default: () => ({}) },
    },
    components: { saveAdd },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择任务',
				edit: '领取人员',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.task.task.useDetail,
			selection: [],
			search: {
				task_name: null,
			},
            dialog: {
				save: false,
			},
            data: [],
            id: "",
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
        async table_yes(row) {
			var reqData = { id: row.id,status:2 }
			var res = await this.$API.task.task.check.post(reqData);
			if (res.code == 1) {
				this.$message.success("操作成功")
                this.setData(this.id)
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
        async setData(data){
            console.log('data :>> ', data);
            this.id = data
            var res = await this.$API.task.task.useDetail.get({id:data});
            if(res.code == 1){
                this.data = res.data
            }
        },
	}
}
</script>

<style></style>
